﻿/*
 *  创建人  李铭
 *  日期 9/15
 *  功能 伙办公寓 or 伙办办公 or  伙办商铺 显示筛选到的房源的基本信息。 首页和子页 进行查询楼盘的业务功能
 *
 * 
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Partner.MVC.Models;
using Newtonsoft.Json;
namespace Partner.MVC.Controllers
{
    public class HouseMessageController : Controller
    {
        GuyEntities db = new GuyEntities();

        /// <summary>
        ///  房源基本信息
        /// </summary>
        /// <param name="House_Id"></param>
        /// <returns></returns>
        public ActionResult HouseMessage(int? House_Id)
        {
            var list = db.House_Source.ToList();
            var arr = from a in list
                      where a.House_Id == House_Id
                      select a;
            ViewBag.list = arr;
            return View();
        }

        /// <summary>
        ///  楼盘名称查询
        /// </summary>
        /// <param name="House_Name"></param>
        /// <returns></returns>
        public ActionResult HouseSearch(string House_Name)
        {
            var list = db.House_Source.Where(a => a.House_State == 1).ToList(); //   0未审核  1通过    2 驳回     3用户删除   4 管理员删除
            //如果没有查询的内容,那就全部显示。
            if (House_Name == "" || House_Name == null)
            {
                ViewBag.list = list;
            }
            else
            {
                ViewBag.list = list.Where(n => n.House_Name.Contains(House_Name)).ToList();
            }
            return View();
        }
        /// <summary>
        /// 预约
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Appointment(House_Appoint model)
        {

            //传递登陆信息
            var user = Session["LoginUser"] as User_Info;

            //判断是否已经预约
            var exists = db.House_Appoint.Where(n => n.App_CreatePeople == user.Use_Id && n.House_Id == model.House_Id).FirstOrDefault();
            model.App_CreatePeople = user.Use_Id;
            model.App_Time = DateTime.Now;
            model.App_CreateTime = DateTime.Now;

            //判断
            if (exists != null)
            {
                return 2;
            }
            else
            {
                db.House_Appoint.Add(model);
                db.SaveChanges();
                return 1;
            }

        }
    }
}
